package dxn.nl.file.client.model.codec;

import dxn.nl.file.client.model.dto.TransferMessageDto;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 自定义信息解码器
 */
public class MessageDecoder extends MessageToMessageDecoder<ByteBuf> {
    private static final Logger logger = LoggerFactory.getLogger(MessageDecoder.class);

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        try {
            TransferMessageDto transferMessageDto = MessageCodeUtil.decode(byteBuf);
            list.add(transferMessageDto);
        } catch (Exception ex) {
            logger.error("", ex);
            throw ex;
        }
    }
}
